package com.xlh.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;

import com.xlh.Utils.FUti;

public class WzmProgressBar extends ProgressBar{
    String text;
    Paint mPaint;


    public WzmProgressBar(Context context) {
        super(context);


        // TODO Auto-generated constructor stub
        System.out.println("1");
        initText();
    }

    public WzmProgressBar(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
        System.out.println("2");
        initText();
    }


    public WzmProgressBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
        System.out.println("3");
        initText();
    }

    @Override
    public synchronized void setProgress(int progress) {
        // TODO Auto-generated method stub
        setText(progress);
        super.setProgress(progress);


    }



    /*
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);

        int width;
        int height;
       // setMeasuredDimension(widthSize, 40);
    }
    */
    @Override
    protected synchronized void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);
        //this.setText();
        Rect rect = new Rect();
        this.mPaint.getTextBounds(this.text, 0, this.text.length(), rect);
        int x = (getWidth() / 2) - rect.centerX();
        int y = (getHeight() / 2) - rect.centerY();

        canvas.drawText(this.text, 2, y, this.mPaint);
        //ViewGroup.LayoutParams lp =  this.getLayoutParams();
      //  lp.height = FUti.dip2px(this.getContext(),60);

    }

    //初始化，画笔
    private void initText(){
        this.mPaint = new Paint();
        this.mPaint.setColor(Color.WHITE);

    }

    private void setText(){
        setText(this.getProgress());
    }

    //设置文字内容
    private void setText(int progress){
        // int i = (progress * 100)/this.getMax();
        // this.text = String.valueOf(i) + "%";
        // this.text = String.valueOf(i) + "%";
    }

    public void setText(String s){
        this.text = s;
    }


    public void setTextSize(int size){
        this.mPaint.setTextSize(size);

    }



}
